public class Solution7 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if(root==null){
            return root;
        }
        if(root==p||root==q){
            return root;
        }
        // 这边只剩下两种情况,在一侧和在两侧
        TreeNode root1=lowestCommonAncestor(root.left,p,q);
        TreeNode root2=lowestCommonAncestor(root.right,p,q);
        if(root1!=null&&root2!=null){
            return root;
        }else if(root1==null&& root2!=null){
            return root2;
        }else{
            return root1;
        }
    }
}
